home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_04 / allison / operate.cpp < prev    next >
C/C++ Source or Header  |  1995-02-06  |  527b  |  30 lines

  1. LISTING 10 - operator+ and operator<< for a complex number data
  2. type
  3.  
  4. #include <iostream.h>
  5.  
  6. struct complex
  7. {
  8.     double real, imag;
  9.  
  10.     complex(double = 0.0, double = 0.0);
  11. };
  12.  
  13. complex::complex(double r, double i)
  14. {
  15.     real = r;
  16.     imag = i;
  17. }
  18.  
  19. inline ostream& operator<<(ostream &os, const complex &c)
  20. {
  21.     os << '(' << c.real << ',' << c.imag << ')';
  22.     return os;
  23. }
  24.  
  25. inline complex operator+(const complex &c1, const complex &c2)
  26. {
  27.     return complex(c1.real+c2.real,c1.imag+c2.imag);
  28. }
  29.  
  30.